/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.common.dto;

import java.util.HashSet;
import java.util.Set;

import com.javaeye.common.dto.DTO;

public class User implements DTO {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5246378027372300440L;
	
	public static final String LOGIN = "userinfo";

	private int id;
	
	private String userName;
	
	private String password;
	
	private String duty;
	
	private String deptId;
	
	private Set<Role> roles = new HashSet<Role>();
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDuty() {
		return duty;
	}

	public void setDuty(String duty) {
		this.duty = duty;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}

	public String getDeptId() {
		return deptId;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public Set<Role> getRoles() {
		return roles;
	}
	
	public String getRoleNames() {
		StringBuffer sb = new StringBuffer();
		for (Role r : roles) {
			sb.append(r.getName());
			sb.append(",");
		}
		return sb.toString();
	}
	
	public void addRole(Role role) {
		roles.add(role);
	}
	
	public void removeRole(Role role) {
		roles.remove(role);
	}
	
	public void removeAllRoles() {
		roles.clear();
	}
	
	public boolean containsRole(int roleId) {
		for (Role r : roles) {
			if (r.getId() == roleId) {
				return true;
			}
		}
		return false;
	}
}
